home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 May / PCWorld_2008-05_cd.bin / Audio-video / audials / audialsTV-setup.exe / [0] / MusicTv.js < prev    next >
Text (UTF-16)  |  2008-03-14  |  61KB  |  893 lines

  1.  
  2. var L_PREVIOUS_TEXT     = "Previous";
  3. var L_PLAY_TEXT         = "Play";
  4. var L_STOP_TEXT         = "Stop";
  5. var L_NEXT_TEXT         = "Next";
  6. var L_MUTE_TEXT         = "Mute";
  7. var L_UNMUTE_TEXT       = "Loud";
  8. var L_VOLUP_TEXT        = "Volume up";
  9. var L_VOLDOWN_TEXT      = "Volume down";
  10. var L_AppName           = "Audials TV";              
  11.  
  12.  
  13. var g_DockedWidth      = 130;
  14. var g_DockedHeight     = 97;
  15.  
  16. var g_toolbarHeight_s  = 23;
  17. var g_toolbarHeight_b  = 33;
  18. var g_toolbarWidth     = 124;
  19. var g_headerHeight_s   = 17;
  20. var g_headerHeight_b   = 23;
  21.  
  22. var g_UnDockedWidth    = 320;
  23. var g_UnDockedHeight   = 240;
  24.  
  25. var g_bAllVisible      = true;
  26. var g_Volume           = 50;
  27. var g_HideDelay        = 3000;
  28.  
  29. var g_bgTileSize       = 40;
  30.  
  31. var restoretimer;
  32.  
  33. var oShell = new ActiveXObject("WScript.Shell");
  34.  
  35. function LoadFlyout()
  36. {
  37.     var table = selectedChannels;
  38.     var player = System.Gadget.document.parentWindow.MusicTv;
  39.     var captionText = System.Gadget.document.parentWindow.captionText;
  40.  
  41.     // Iterate through the rows.
  42.     var channelID = player.GetNextChannel(0);
  43.     while(channelID != 0) 
  44.     {
  45.         var bSelected = player.IsChannelSelected(channelID);
  46.         if(bSelected)
  47.         {
  48.             var row = table.insertRow();   
  49.             row.height = 12;
  50.             var cell = row.insertCell();
  51.             var channelName = player.GetChannelName(channelID);
  52.             cell.innerText = channelName;
  53.             cell.onclick = OnChannelClick;
  54.             cell.id = channelID; 
  55.             cell.onmouseenter = OnChannelHover;
  56.             cell.onmouseout = OnChannelOut;
  57.             cell.style.color = "white";
  58.             cell.style.width = 140;
  59.             
  60.             if(captionText && captionText.innerText == channelName)
  61.             {
  62.                 cell.style.backgroundColor = "#323232";
  63.                 cell.style.color = "white";
  64.             }
  65.         }
  66.         
  67.         channelID = player.GetNextChannel(channelID);
  68.     }       
  69. }
  70.  
  71. function OnSenderHover()
  72. {
  73.         var oImg = System.Gadget.Flyout.document.getElementById("channels-sender");
  74.         oImg.src = 'resources/toolbar_big/channels_sender_hov.png';
  75. }
  76.  
  77. function OnSenderOut()
  78. {
  79.         var oImg = System.Gadget.Flyout.document.getElementById("channels-sender");
  80.         oImg.src = 'resources/toolbar_big/channels_sender_rest.png';
  81. }
  82.  
  83. function OnSenderClick()
  84. {
  85.         // There is no way to open the settings UI directly,
  86.         // so we simulate key presses:
  87.         //   <shift-F10> opens the context menu
  88.         //   2x <arrow up>
  89.         //   <enter>
  90.         // (using the 'o' hotkey from Options isn't safe enough
  91.         // for other languages than german/english)
  92.     //
  93.         // The context menu can only be opened if the flyout
  94.         // is closed. We register an onHide handler, close the
  95.         // the flyout and send the proper keystrokes inside the
  96.         // event handler.
  97.         System.Gadget.Flyout.onHide = OnSenderClick2;
  98.         // close the flyout
  99.         System.Gadget.Flyout.show = false;
  100. }
  101. function OnSenderClick2() {
  102.         // reset event handler
  103.         System.Gadget.Flyout.onHide = function() {};
  104.         // send keys to open settings UI
  105.         oShell.SendKeys('+{F10}{UP 2}{ENTER}');
  106. }
  107.  
  108. function OnChannelHover()
  109. {
  110.     this.style.color = "#9f9f9f";
  111. }
  112. function OnChannelOut()
  113. {
  114.     this.style.color = "white";
  115. }
  116.  
  117. function OnChannelClick()
  118. {
  119.     var player = System.Gadget.document.parentWindow.MusicTv;
  120.     System.Gadget.document.parentWindow.storage.innerText = this.id;
  121.     player.PlayChannel(this.id);
  122.     
  123.     System.Gadget.document.parentWindow.bar_play.style.display="none";
  124.     System.Gadget.document.parentWindow.bar_stop.style.display="";
  125.  
  126.     System.Gadget.document.parentWindow.barB_play.style.display="none";
  127.     System.Gadget.document.parentWindow.barB_stop.style.display="";
  128.  
  129.     var channelName = player.GetChannelName(this.id);
  130.     var headerText = System.Gadget.document.parentWindow.captionText;
  131.     headerText.innerText = channelName;
  132.     
  133.     // hide channel list
  134.     ShowChannels();
  135. }
  136.  
  137. function ShowChannels()
  138. {
  139.     if(System.Gadget.Flyout.show)
  140.     {
  141.         System.Gadget.Flyout.show = false;
  142.         System.Gadget.document.parentWindow.head_s_channels_in.style.display="none";
  143.         System.Gadget.document.parentWindow.head_s_channels_out.style.display="";
  144.         System.Gadget.document.parentWindow.head_b_channels_in.style.display="none";
  145.         System.Gadget.document.parentWindow.head_b_channels_out.style.display="";
  146.     }
  147.     else
  148.     {
  149.         System.Gadget.Flyout.show = true;
  150.         System.Gadget.document.parentWindow.head_s_channels_in.style.display="";
  151.         System.Gadget.document.parentWindow.head_s_channels_out.style.display="none";
  152.         System.Gadget.document.parentWindow.head_b_channels_in.style.display="";
  153.         System.Gadget.document.parentWindow.head_b_channels_out.style.display="none";
  154.     }
  155. }
  156.  
  157. function LoadSettings()
  158. {  
  159.     var table = allChannels;
  160.     var player = System.Gadget.document.parentWindow.MusicTv;
  161.     
  162.     // Iterate through the rows.
  163.     var channelID = player.GetNextChannel(0);
  164.     while(channelID != 0) 
  165.     {
  166.         var bSelected = player.IsChannelSelected(channelID);
  167.         var strName = player.GetChannelName(channelID);
  168.         var strGenre = player.GetChannelGenre(channelID);
  169.         var strLanguage = player.GetChannelLanguage(channelID);
  170.  
  171.         var row = table.insertRow(); 
  172.              
  173.         var cellck = row.insertCell();
  174.         if(bSelected)
  175.             cellck.innerHTML = "<input type='checkbox' checked = true >";
  176.         else
  177.             cellck.innerHTML = "<input type='checkbox'>";
  178.         
  179.         cellck.onclick = OnSelectChannel;
  180.         cellck.id = channelID;
  181.         cellck.width = 20;
  182.  
  183.         var cellName = row.insertCell();
  184.         cellName.innerText = strName;
  185.         cellName.width = 130;
  186.  
  187.         var cellGenre = row.insertCell();
  188.         cellGenre.innerText = strGenre;
  189.         cellGenre.width = 65;
  190.  
  191.         var cellLanguage = row.insertCell();
  192.         cellLanguage.innerText = strLanguage;
  193.         cellLanguage.width = 65;
  194.                 
  195.         channelID = player.GetNextChannel(channelID);
  196.     }
  197. }
  198.  
  199. function OnSelectChannel()
  200. {
  201.     var player = System.Gadget.document.parentWindow.MusicTv;
  202.     
  203.     var bSelected = player.IsChannelselected(this.id)
  204.     if(bSelected)
  205.         player.MarkChannel(this.id, false);
  206.     else
  207.         player.MarkChannel(this.id, true);
  208. }
  209.  
  210. // read application settings
  211. function GetAudialsTVSettings()
  212. {  
  213.     this.g_Volume               = System.Gadget.Settings.read("LastVolume");
  214.     if(g_Volume == "")
  215.         g_Volume = 50;
  216.     var channel = System.Gadget.Settings.read("LastChannel");
  217.     if(channel == "")
  218.         channel = GetNextSelectedChannel(0);
  219.     System.Gadget.document.parentWindow.storage.innerText = channel;
  220. }
  221.  
  222. // save application settings
  223. function PutAudialsTVSettings()
  224. {
  225.     System.Gadget.Settings.write("LastVolume", g_Volume);
  226.     var channel =System.Gadget.document.parentWindow.storage.innerText;
  227.     if(channel == "")
  228.         channel = GetNextSelectedChannel(0);
  229.     
  230.     System.Gadget.Settings.write("LastChannel", channel);
  231. }
  232.  
  233. function GadgetUnload()
  234. {
  235.     MusicTv.ShutDown();
  236.     PutAudialsTVSettings();
  237. }
  238.  
  239. function GadgetLoad()
  240. {
  241.     System.Gadget.document.parentWindow.storage.style.visibility = "hidden";
  242.     
  243.     MusicTv.InitializeControl();
  244.     MusicTv.UpdateChannelList("http://musictv.audials.com/updatechannels_gadget.txt");
  245.  
  246.     GetAudialsTVSettings();
  247.         
  248.     var currentChanelID =System.Gadget.document.parentWindow.storage.innerText;
  249.     MusicTv.PlayChannel(currentChanelID);
  250.     var channelName = MusicTv.GetChannelName(currentChanelID);
  251.     captionText.innerText = channelName;
  252.     MusicTv.SetVolume(g_Volume);
  253.     
  254.     HideToolbars();
  255.     System.Gadget.settingsUI = "settings.html";
  256.     System.Gadget.Flyout.file = "flyout.html";
  257.     System.Gadget.onUndock = ViewVideo;
  258.     System.Gadget.onDock = ViewVideo;
  259.     
  260.     // make the navigation bar
  261.     //gPageDir = document.getElementsByTagName("html")[0].dir;  
  262.     smallToolbar.innerHTML = "prev play stop next volUP volDOWN mute unmute";
  263.     bigToolbar.innerHTML = "prev play stop next volUP volDOWN mute unmute";
  264.     MakeBigHeader();
  265.     MakeSmallHeader();
  266.     MakeSmallToolbar(smallToolbar);
  267.     MakeBigToolbar(bigToolbar);
  268.     setAltLabels(); 
  269.  
  270.     head_s_channels_in.style.display="none";
  271.     head_s_channels_out.style.display="";
  272.     head_b_channels_in.style.display="none";
  273.     head_b_channels_out.style.display="";
  274.     
  275.     bar_play.style.display="none";
  276.     bar_stop.style.display="";
  277.     barB_play.style.display="none";
  278.     barB_stop.style.display="";
  279.  
  280.     bar_mute.style.display="";
  281.     bar_unmute.style.display="none";   
  282.     barB_mute.style.display="";
  283.     barB_unmute.style.display="none";   
  284. }
  285.  
  286. // creates toolbar
  287. function MakeSmallToolbar(controlsString)
  288. {
  289.     var controlsArray=controlsString.innerText.split(" ");
  290.     var controlName;
  291.     var newImageToAdd;
  292.     var newLabelToAdd;
  293.     var labelsForRollovers = "";
  294.     var imageRollovers = "<div id='smallBkgBar'></div><div id='smallButtonBar'>";
  295.     var i=0;
  296.     while(controlName=controlsArray[i++])
  297.     {
  298.         var controlNameAction = controlName;
  299.         newImageToAdd = "<a id='link_" + controlNameAction + "' href='javascript:void(0);' onClick='this.blur();'>"
  300.             + "<img border=0 id='bar_" + controlNameAction + "' hspace='1' src='resources/toolbar_small/"+controlName+"_rest.png' "
  301.             + "onMouseOver='src=\"resources/toolbar_small/" + controlName + "_hov.png\"' onMouseOut='src=\"resources/toolbar_small/" + controlName + "_rest.png\"' "
  302.             + "onMouseDown='src=\"resources/toolbar_small/" + controlName + "_down.png\"' onMouseUp='src=\"resources/toolbar_small/" + controlName + "_hov.png\";"
  303.             + "onAction(\"" + controlNameAction + "\");' \>"
  304.             + "</a>";
  305.         newLabelToAdd = "<label for='link_"+controlName+"'>"+controlName+"</label>";
  306.  
  307.         imageRollovers += newImageToAdd;
  308.         labelsForRollovers += newLabelToAdd;
  309.     }
  310.     imageRollovers += "</div>";
  311.     controlsString.innerHTML=imageRollovers;
  312.     //tooltips.innerHTML=labelsForRollovers;      
  313. }
  314.  
  315. function MakeBigToolbar(bigToolbar)
  316. {
  317.     var controlsArray=bigToolbar.innerText.split(" ");
  318.     var controlName;
  319.     var newImageToAdd;
  320.     var newLabelToAdd;
  321.     var labelsForRollovers = "";
  322.     var imageRollovers =  "<div class='toolbutton' id='bigBkgBarL'></div>";
  323.         imageRollovers += "<div class='toolbutton' id='bigBkgBarC'></div>";
  324.         imageRollovers += "<div class='toolbutton' id='bigBkgBarR'></div>";
  325.         imageRollovers += "<div id='bigButtonBar'>";
  326.     var i=0;
  327.     while(controlName=controlsArray[i++])
  328.     {
  329.         var controlNameAction = controlName;
  330.         newImageToAdd = "<a class='toolbutton' id='link_" + controlNameAction + "' href='javascript:void(0);' onClick='this.blur();'>"
  331.             + "<img class='toolbutton' id='barB_" + controlNameAction + "' hspace='0' src='resources/toolbar_big/"+controlName+"_rest.png' "
  332.             + "onMouseOver='src=\"resources/toolbar_big/" + controlName + "_hov.png\"' onMouseOut='src=\"resources/toolbar_big/" + controlName + "_rest.png\"' "
  333.             + "onMouseDown='src=\"resources/toolbar_big/" + controlName + "_down.png\"' onMouseUp='src=\"resources/toolbar_big/" + controlName + "_hov.png\";"
  334.             + "onAction(\"" + controlNameAction + "\");' \>"
  335.             + "</a>";
  336.         newLabelToAdd = "<label for='link_"+controlName+"'>"+controlName+"</label>";
  337.  
  338.         // i don't know how to make space. please make it better Cristi
  339.         if (i == 5)
  340.             imageRollovers += " ";
  341.             
  342.         imageRollovers += newImageToAdd;
  343.         labelsForRollovers += newLabelToAdd;
  344.     }
  345.     imageRollovers += "</div>";
  346.     bigToolbar.innerHTML=imageRollovers;
  347.     //tooltips.innerHTML=labelsForRollovers;      
  348.     
  349.     AddSizeButtons(bigToolbar);
  350. }
  351.  
  352. function AddSizeButtons(bigToolbar)
  353. {
  354.     var sizeButtons = "size_1x size_2x size_4x";
  355.     var controlsArray=sizeButtons.split(" ");
  356.     var controlName;
  357.     var divSizeButtons = "<div id='bigSizeBar'>";
  358.     var i=0;
  359.     while(controlName=controlsArray[i++])
  360.     {
  361.         var controlNameAction = controlName;
  362.         newSizeButton = "<a id='link_" + controlNameAction + "' href='javascript:void(0);' onClick='this.blur();'>"
  363.             + "<img border=0 id='barB_" + controlNameAction + "' hspace='0' src='resources/toolbar_big/"+controlName+"_rest.png' "
  364.             + "onMouseOver='src=\"resources/toolbar_big/" + controlName + "_hov.png\"' onMouseOut='src=\"resources/toolbar_big/" + controlName + "_rest.png\"' "
  365.             + "onMouseDown='src=\"resources/toolbar_big/" + controlName + "_down.png\"' onMouseUp='src=\"resources/toolbar_big/" + controlName + "_hov.png\";"
  366.             + "onAction(\"" + controlNameAction + "\");' \>"
  367.             + "</a>";
  368.  
  369.         divSizeButtons += newSizeButton;
  370.     }
  371.     divSizeButtons += "</div>";
  372.     
  373.     bigToolbar.innerHTML += divSizeButtons;
  374. }
  375.  
  376. // creates header toolbar
  377. function MakeBigHeader()
  378. {
  379.  
  380.     var head_buttons =  "<div class='toolbutton' id='bigHeaderBkgL'></div>";
  381.         head_buttons += "<div class='toolbutton' id='bigHeaderBkgC'></div>";
  382.         head_buttons += "<div class='toolbutton' id='bigHeaderBkgR'></div>";
  383.         head_buttons += "<div id='bigHeaderButtons'>";
  384.  
  385.     var controlName = "channels_out";
  386.     var ButtonOut = "<a id='link_" + controlName + "' href='javascript:void(0);' onClick='this.blur();'>"
  387.         + "<img border=0 id='head_b_" + controlName + "' hspace='1' src='resources/toolbar_big/"+controlName+"_rest.png' "
  388.         + "onMouseOver='src=\"resources/toolbar_big/" + controlName + "_hov.png\"' onMouseOut='src=\"resources/toolbar_big/" + controlName + "_rest.png\"' "
  389.         + "onMouseDown='src=\"resources/toolbar_big/" + controlName + "_down.png\"' onMouseUp='src=\"resources/toolbar_big/" + controlName + "_hov.png\";"
  390.         + "onAction(\"" + controlName + "\");' \>"
  391.         + "</a>";
  392.     head_buttons += ButtonOut;
  393.     controlName = "channels_in";
  394.     var ButtonIn = "<a id='link_" + controlName + "' href='javascript:void(0);' onClick='this.blur();'>"
  395.         + "<img border=0 id='head_b_" + controlName + "' hspace='1' src='resources/toolbar_big/"+controlName+"_rest.png' "
  396.         + "onMouseOver='src=\"resources/toolbar_big/" + controlName + "_hov.png\"' onMouseOut='src=\"resources/toolbar_big/" + controlName + "_rest.png\"' "
  397.         + "onMouseDown='src=\"resources/toolbar_big/" + controlName + "_down.png\"' onMouseUp='src=\"resources/toolbar_big/" + controlName + "_hov.png\";"
  398.         + "onAction(\"" + controlName + "\");' \>"
  399.         + "</a>";
  400.     head_buttons += ButtonIn;
  401.     head_buttons += "</div>"
  402.     bigHeader.innerHTML += head_buttons;
  403. }
  404.  
  405. function MakeSmallHeader()
  406. {
  407.     var head_buttons = "<div>"
  408.     var controlName = "channels_out";
  409.     var ButtonOut = "<a id='link_" + controlName + "' href='javascript:void(0);' onClick='this.blur();'>"
  410.         + "<img border=0 id='head_s_" + controlName + "' hspace='1' src='resources/toolbar_small/"+controlName+"_rest.png' "
  411.         + "onMouseOver='src=\"resources/toolbar_small/" + controlName + "_hov.png\"' onMouseOut='src=\"resources/toolbar_small/" + controlName + "_rest.png\"' "
  412.         + "onMouseDown='src=\"resources/toolbar_small/" + controlName + "_down.png\"' onMouseUp='src=\"resources/toolbar_small/" + controlName + "_hov.png\";"
  413.         + "onAction(\"" + controlName + "\");' \>"
  414.         + "</a>";
  415.     head_buttons += ButtonOut;
  416.     controlName = "channels_in";
  417.     var ButtonIn = "<a id='link_" + controlName + "' href='javascript:void(0);' onClick='this.blur();'>"
  418.         + "<img border=0 id='head_s_" + controlName + "' hspace='1' src='resources/toolbar_small/"+controlName+"_rest.png' "
  419.         + "onMouseOver='src=\"resources/toolbar_small/" + controlName + "_hov.png\"' onMouseOut='src=\"resources/toolbar_small/" + controlName + "_rest.png\"' "
  420.         + "onMouseDown='src=\"resources/toolbar_small/" + controlName + "_down.png\"' onMouseUp='src=\"resources/toolbar_small/" + controlName + "_hov.png\";"
  421.         + "onAction(\"" + controlName + "\");' \>"
  422.         + "</a>";
  423.     head_buttons += ButtonIn;
  424.     head_buttons += "</div>"
  425.     smallHeader.innerHTML += head_buttons;
  426. }
  427.  
  428.  
  429. // set's alt tabs for navigation;
  430. function setAltLabels()
  431. {
  432.     bar_prev.setAttribute("alt",L_PREVIOUS_TEXT);
  433.     bar_play.setAttribute("alt",L_PLAY_TEXT);
  434.     bar_stop.setAttribute("alt",L_STOP_TEXT);
  435.     bar_next.setAttribute("alt",L_NEXT_TEXT);
  436.     bar_mute.setAttribute("alt",L_MUTE_TEXT);
  437.     bar_unmute.setAttribute("alt",L_UNMUTE_TEXT);
  438.     bar_volUP.setAttribute("alt",L_VOLUP_TEXT);
  439.     bar_volDOWN.setAttribute("alt",L_VOLDOWN_TEXT);
  440.  
  441.     barB_prev.setAttribute("alt",L_PREVIOUS_TEXT);
  442.     barB_play.setAttribute("alt",L_PLAY_TEXT);
  443.     barB_stop.setAttribute("alt",L_STOP_TEXT);
  444.     barB_next.setAttribute("alt",L_NEXT_TEXT);
  445.     barB_mute.setAttribute("alt",L_MUTE_TEXT);
  446.     barB_unmute.setAttribute("alt",L_UNMUTE_TEXT);
  447.     barB_volUP.setAttribute("alt",L_VOLUP_TEXT);
  448.     barB_volDOWN.setAttribute("alt",L_VOLDOWN_TEXT);
  449. }
  450.  
  451. // navigation controls
  452. function onAction(action)
  453. {
  454.     if (event.button == 2 || event.button == 3)
  455.     {
  456.         return false
  457.     }
  458.     else
  459.     {
  460.         var player = System.Gadget.document.parentWindow.MusicTv;
  461.         
  462.         switch(action)
  463.         {
  464.             case "prev":
  465.             {
  466.                 bar_play.style.display="none";
  467.                 bar_stop.style.display="";
  468.                 barB_play.style.display="none";
  469.                 barB_stop.style.display="";
  470.             
  471.                 var currentChanelID = System.Gadget.document.parentWindow.storage.innerText;
  472.                 var prevChannel = GetPreviousSelectedChannel(currentChanelID);
  473.                 
  474.                 if(prevChannel == 0)
  475.                 {
  476.                    player.Stop();
  477.                 }
  478.                 else
  479.                 {
  480.                     currentChanelID = prevChannel;
  481.                     System.Gadget.document.parentWindow.storage.innerText = currentChanelID;
  482.                     player.PlayChannel(currentChanelID);
  483.                 
  484.                     var channelName = player.GetChannelName(currentChanelID);
  485.                     captionText.innerText = channelName;                
  486.                 }
  487.             }break;
  488.             case "play":
  489.             {
  490.                 bar_play.style.display="none";
  491.                 bar_stop.style.display="";
  492.                 barB_play.style.display="none";
  493.                 barB_stop.style.display="";
  494.                 
  495.                 var currentChanelID = System.Gadget.document.parentWindow.storage.innerText;
  496.                 player.PlayChannel(currentChanelID);
  497.                 
  498.                 var channelName = player.GetChannelName(currentChanelID);
  499.                 captionText.innerText = channelName;    
  500.                             
  501.             }break;
  502.             case "stop":
  503.             {
  504.                 bar_play.style.display="";
  505.                 bar_stop.style.display="none";
  506.                 barB_play.style.display="";
  507.                 barB_stop.style.display="none";
  508.                 
  509.                 player.Stop();
  510.             }break;
  511.             case "next":
  512.             {
  513.                 bar_play.style.display="none";
  514.                 bar_stop.style.display="";
  515.                 barB_play.style.display="none";
  516.                 barB_stop.style.display="";
  517.                 
  518.                 var currentChanelID = System.Gadget.document.parentWindow.storage.innerText;
  519.                 var nextChannel = GetNextSelectedChannel(currentChanelID);
  520.                 
  521.                 if(nextChannel == 0)
  522.                 {
  523.                    player.Stop();
  524.                 }
  525.                 else
  526.                 {
  527.                     currentChanelID = nextChannel;
  528.                     System.Gadget.document.parentWindow.storage.innerText = currentChanelID;                    
  529.                     player.PlayChannel(currentChanelID);
  530.                                     
  531.                     var channelName = player.GetChannelName(currentChanelID);
  532.                     captionText.innerText = channelName;                                        
  533.                 }
  534.             }break;
  535.             case "volUP":
  536.             {
  537.                 if(g_Volume < 100)
  538.                 {
  539.                     g_Volume += 10;
  540.                     player.SetVolume(g_Volume);
  541.                 }
  542.             }break;
  543.             case "volDOWN":
  544.             {
  545.                 if(g_Volume > 0)
  546.                 {
  547.                     g_Volume -= 10;
  548.                     player.SetVolume(g_Volume);
  549.                 }
  550.             }break;
  551.             case "mute":
  552.             {
  553.                 bar_mute.style.display="none";
  554.                 bar_unmute.style.display="";
  555.                 barB_mute.style.display="none";
  556.                 barB_unmute.style.display="";
  557.                 
  558.                 player.Mute(true);
  559.             }break;
  560.             case "unmute":
  561.             {
  562.                 bar_mute.style.display="";
  563.                 bar_unmute.style.display="none";
  564.                 barB_mute.style.display="";
  565.                 barB_unmute.style.display="none";
  566.                 
  567.                 player.Mute(false);
  568.             }break;
  569.             case "channels_in":
  570.             case "channels_out":
  571.             {
  572.                 ShowChannels();
  573.             }break;
  574.             case "size_1x":
  575.             {
  576.                 g_UnDockedWidth    = 320;
  577.                 g_UnDockedHeight   = 240;
  578.                 ViewAll();
  579.             }break;
  580.             case "size_2x":
  581.             {
  582.                 g_UnDockedWidth    = 640;
  583.                 g_UnDockedHeight   = 480;
  584.                 ViewAll();
  585.             }break;
  586.             case "size_4x":
  587.             {
  588.                 g_UnDockedWidth    = 960;
  589.                 g_UnDockedHeight   = 720;
  590.                 ViewAll();
  591.             }break;
  592.         }
  593.     }
  594. }
  595.  
  596. function GetNextSelectedChannel(currentChannel)
  597. {
  598.     var player = System.Gadget.document.parentWindow.MusicTv;
  599.     
  600.     // iterate from current
  601.     var nextChannel = player.GetNextChannel(currentChannel);
  602.     while(nextChannel)
  603.     {
  604.         if(player.IsChannelSelected(nextChannel))
  605.             return nextChannel;
  606.     
  607.         nextChannel = player.GetNextChannel(nextChannel);
  608.     }
  609.     
  610.     // start from first one
  611.     nextChannel = player.GetNextChannel(0);
  612.     while(nextChannel)
  613.     {
  614.         if(player.IsChannelSelected(nextChannel))
  615.             return nextChannel;
  616.     
  617.         nextChannel = player.GetNextChannel(nextChannel);
  618.     }
  619.     
  620.     return 0;
  621. }
  622.  
  623. function GetPreviousSelectedChannel(currentChannel)
  624. {
  625.     var player = System.Gadget.document.parentWindow.MusicTv;
  626.     
  627.     // iterate from current
  628.     var prevChannel = player.GetPreviousChannel(currentChannel);
  629.     while(prevChannel)
  630.     {
  631.         if(player.IsChannelSelected(prevChannel))
  632.             return prevChannel;
  633.     
  634.         prevChannel = player.GetPreviousChannel(prevChannel);
  635.     }
  636.     
  637.     // start from last one
  638.     prevChannel = player.GetPreviousChannel(0);
  639.     while(prevChannel)
  640.     {
  641.         if(player.IsChannelSelected(prevChannel))
  642.             return prevChannel;
  643.     
  644.         prevChannel = player.GetPreviousChannel(prevChannel);
  645.     }
  646.     
  647.     return 0;
  648. }
  649.  
  650. function MouseOut()
  651. {
  652.     if(event.toElement)
  653.     {
  654.         return;
  655.     }   
  656.     clearTimeout(restoretimer);
  657.     restoretimer = setTimeout(HideToolbars, g_HideDelay);
  658. }
  659.  
  660. function MouseIn()
  661. {    
  662.     clearTimeout(restoretimer);
  663.     if(event.fromElement)
  664.     {
  665.         return;
  666.     }
  667.     ShowToolbars();    
  668.     clearTimeout(restoretimer);
  669. }
  670.  
  671. function MoveOnVideo()
  672. {
  673.      ViewAll();
  674.      //ShowToolbars();
  675. }
  676.  
  677. function ShowToolbars()
  678. {
  679.     if(g_bAllVisible)
  680.         return;    
  681.     
  682.     ViewAll();
  683. }
  684.  
  685. function HideToolbars()
  686. {
  687.     if(!g_bAllVisible)
  688.         return;    
  689.  
  690.     if(System.Gadget.Flyout.show)
  691.             return;        // gadget flyout is visible, do not hide toolbars
  692.             
  693.     ViewVideo();
  694. }
  695.  
  696. function ViewVideo()
  697. {        
  698.     clearTimeout(restoretimer);
  699.  
  700.     if(!System.Gadget.docked) 
  701.     {   
  702.         //undocked
  703.         with(document.body.style)
  704.             margin= 0,
  705.             width = g_UnDockedWidth,
  706.             height= g_UnDockedHeight + g_toolbarHeight_b + g_headerHeight_b;
  707.  
  708.         smallHeader.style.visibility= "hidden",
  709.         bigHeader.style.visibility= "hidden",
  710.         captionText.style.visibility = "hidden";
  711.              
  712.         with(MusicTv.style)
  713.             width = g_UnDockedWidth,
  714.             height= g_UnDockedHeight,
  715.             top   = g_headerHeight_b,
  716.             left  = 0;
  717.         
  718.         with(smallToolbar.style)
  719.             visibility= "hidden";            
  720.             
  721.         with(bigToolbar.style)
  722.             visibility= "hidden";            
  723.     }
  724.     else
  725.     {
  726.         //docked
  727.         with(document.body.style)
  728.             margin= 0,
  729.             width = g_DockedWidth,
  730.             height= g_DockedHeight + g_toolbarHeight_s + g_headerHeight_s;
  731.  
  732.         smallHeader.style.visibility= "hidden",
  733.         bigHeader.style.visibility= "hidden",
  734.         captionText.style.visibility = "hidden";
  735.              
  736.         with(MusicTv.style)
  737.             width = g_DockedWidth,
  738.             height= g_DockedHeight,
  739.             top   = g_headerHeight_s,
  740.             left  = 0;
  741.         
  742.         with(smallToolbar.style)
  743.             visibility= "hidden";            
  744.  
  745.         with(bigToolbar.style)
  746.             visibility= "hidden";            
  747.     }
  748.  
  749.     g_bAllVisible = false;
  750. }
  751.  
  752. function ViewAll()
  753. {
  754.     clearTimeout(restoretimer);
  755.     restoretimer = setTimeout(HideToolbars, g_HideDelay);
  756.  
  757.     if(!System.Gadget.docked) 
  758.     {   
  759.         //undocked
  760.         with(document.body.style)
  761.             margin= 0,
  762.             width = g_UnDockedWidth,
  763.             height= g_UnDockedHeight + g_toolbarHeight_b + g_headerHeight_b;
  764.  
  765.         with(bigHeaderBkgC.style)
  766.             width = g_UnDockedWidth - 2*g_bgTileSize;
  767.         with(bigHeaderBkgR.style)
  768.             left = g_UnDockedWidth - g_bgTileSize;
  769.  
  770.         with(bigHeader.style)
  771.             width = g_UnDockedWidth,
  772.             height= g_headerHeight_b,
  773.             visibility= "visible";
  774.             
  775.         with(captionText.style)
  776.             visibility = "visible",
  777.             top = 3,
  778.             left = 50,
  779.             height = 19,
  780.             width = 220,
  781.             fontSize = 12,
  782.             fontWeight = "bold";
  783.         smallHeader.style.visibility = "hidden";
  784.              
  785.         with(MusicTv.style)
  786.             width = g_UnDockedWidth,
  787.             height= g_UnDockedHeight,
  788.             top   = g_headerHeight_b,
  789.             left  = 0;
  790.         
  791.         with(smallToolbar.style)
  792.             visibility= "hidden";            
  793.  
  794.         with(bigBkgBarC.style)
  795.             width = g_UnDockedWidth - 2*g_bgTileSize;
  796.         with(bigBkgBarR.style)
  797.             left = g_UnDockedWidth - g_bgTileSize;
  798.                 
  799.         with(bigToolbar.style)
  800.             visibility= "visible",
  801.             width = g_UnDockedWidth,
  802.             height= g_toolbarHeight_b,
  803.             top   = g_UnDockedHeight + g_headerHeight_b,
  804.             left  = 0;
  805.     }
  806.     else
  807.     {
  808.         //docked
  809.         with(document.body.style)
  810.             margin= 0,
  811.             width = g_DockedWidth,
  812.             height= g_DockedHeight + g_toolbarHeight_s + g_headerHeight_s;
  813.  
  814.         with(smallHeader.style)
  815.             width = g_DockedWidth,
  816.             height= g_headerHeight_s,
  817.             visibility= "visible",               
  818.             backgroundImage = "url(resources/header_bkg_s.png)";            
  819.         with(captionText.style)
  820.             visibility = "visible",
  821.             top = 2,
  822.             left = 30,
  823.             height = 15,
  824.             width = 100,
  825.             fontSize = 11,
  826.             fontWeight = "normal";
  827.         bigHeader.style.visibility = "hidden";
  828.              
  829.         with(MusicTv.style)
  830.             width = g_DockedWidth,
  831.             height= g_DockedHeight,
  832.             top   = g_headerHeight_s,
  833.             left  = 0;
  834.         
  835.         with(smallToolbar.style)
  836.             width = g_toolbarWidth,
  837.             height= g_toolbarHeight_s,
  838.             top   = g_DockedHeight + g_headerHeight_s,
  839.             left  = (g_DockedWidth - g_toolbarWidth)/2,
  840.             visibility= "visible";            
  841.  
  842.         with(bigToolbar.style)
  843.             visibility= "hidden";            
  844.     }
  845.  
  846.     g_bAllVisible = true;
  847.  
  848. function PlayInvoked()
  849. {
  850.     var player = System.Gadget.document.parentWindow.MusicTv;
  851.  
  852.     bar_play.style.display="none";
  853.     bar_stop.style.display="";
  854.     barB_play.style.display="none";
  855.     barB_stop.style.display="";
  856.     
  857.     var currentChanelID = System.Gadget.document.parentWindow.storage.innerText;
  858.     player.PlayChannel(currentChanelID);
  859.     
  860.     var channelName = player.GetChannelName(currentChanelID);
  861.     captionText.innerText = channelName;                
  862. }
  863.  
  864. function SwitchToNext()
  865. {
  866.     var player = System.Gadget.document.parentWindow.MusicTv;
  867.     var currentChanelID = System.Gadget.document.parentWindow.storage.innerText;
  868.     var nextChannel = GetNextSelectedChannel(currentChanelID);
  869.     
  870.     if(nextChannel == 0)
  871.     {
  872.         player.Stop();
  873.     }
  874.     else
  875.     {
  876.         currentChanelID = nextChannel;
  877.         System.Gadget.document.parentWindow.storage.innerText = currentChanelID;                    
  878.         player.PlayChannel(currentChanelID);
  879.                         
  880.         var channelName = player.GetChannelName(currentChanelID);
  881.         captionText.innerText = channelName;                                        
  882.     }
  883. }
  884.  
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891.  
  892.